package com.alibaba.cheetah.index;

import java.io.File;

import com.alibaba.cheetah.doc.DocumentBuilder;

public class Indexer {

	private IndexWriter indexWriter = new IndexWriter();

	private DocumentBuilder docBuilder = new DocumentBuilder();

	public void makeIndex(String... basePaths) {
		for (String basePath : basePaths) {
			_makeIndex(basePath);
		}
	}

	private void _makeIndex(String path) {
		if (path == null) {
			return;
		}

		File dir = new File(path);
		File[] files = dir.listFiles();

		if (files == null || files.length == 0) {
			return;
		}

		for (File file : files) {
			if (file.isDirectory()) {
				makeIndex(path + File.separator + file.getName());
			} else {
				indexWriter.addDocument(docBuilder.build(file));
			}
		}
	}

}
